/*
 * @Author: Y先森
 * @Date: 2023-04-28 11:32:34
 * @LastEditors: y && 250048395@qq.com
 * @LastEditTime: 2023-04-28 11:50:38
 * @FilePath: \y-website\src\directives\modules\lazy.js
 */
import { useIntersectionObserver } from '@vueuse/core'
export default {
    mounted(el){
        // 1. 拿到当前 Img 的src
        const imgSrc = el.src
        // 2. 把 src 变为 空
        el.src = ''
        const { stop } = useIntersectionObserver(el,([{isIntersecting}]) => {
            if(isIntersecting){
                // 3. 当图片可见，进行赋值
                el.src = imgSrc
                // 4. 停止监听
                stop()
            }
        })
        
    }
}